﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 坐标平移与缩放
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = this.CreateGraphics();
            g.Clear(Color.White);
            Pen myPen = new Pen(Color.Red, 3);
            g.DrawRectangle(myPen, 0, 0, 200, 100);
            g.DrawEllipse(myPen, 0, 0, 200, 100);
            g.Dispose();
            myPen.Dispose();
        }
        int i;
        private void button1_Click(object sender, EventArgs e)
        {
            {
                if (i == 0)
                {
                    Graphics g = this.CreateGraphics();
                    g.Clear(Color.White);
                    Pen myPen = new Pen(Color.Red, 3);
                    g.TranslateTransform(30, 120);
                    g.DrawRectangle(myPen, 0, 0, 200, 100);
                    g.DrawEllipse(myPen, 0, 0, 200, 100);
                    g.Dispose();
                    myPen.Dispose();
                    button1.Text = ("平移");
                    i = 1;
                }
                else
                {
                    Graphics g = this.CreateGraphics();
                    g.Clear(Color.White);
                    Pen myPen = new Pen(Color.Red, 3);
                    g.DrawRectangle(myPen, 0, 0, 200, 100);
                    g.DrawEllipse(myPen, 0, 0, 200, 100);
                    g.Dispose();
                    myPen.Dispose();
                    button1.Text = ("还原");
                    i = 0;
                }
            }
        }

    }
}
